package com.xk857.forum.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xk857.entities.Forum;
import com.xk857.forum.req.ForumUserREQ;
import com.xk857.forum.service.IForumService;
import com.xk857.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 星空小屋-论坛话题表 前端控制器
 *
 * @author CV大魔王
 * @since 2021-02-23
 */
@RestController
@Api(value = "论坛话题接口", tags = "论坛话题接口")
@RequestMapping("/pri/forum")
public class ForumController {

    @Autowired
    private IForumService forumService;

    @ApiOperation("修改话题信息接口")
    @PutMapping
    public Result update(@RequestBody Forum forum) {
        return Result.ok(forumService.updateOrSave(forum));
    }


    @ApiOperation("新增话题信息接口")
    @PostMapping
    public Result save(@RequestBody Forum forum) {
        return Result.ok(forumService.updateOrSave(forum));
    }


    @ApiImplicitParam(name = "id", value = "话题ID", required = true)
    @ApiOperation("删除话题接口")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id) {
        forumService.deleteById(id);
        return Result.ok();
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "话题ID", required = true),
            @ApiImplicitParam(name = "count", value = "点赞数", required = true)})
    @ApiOperation("更新点赞数")
    @PutMapping("/thumb/{id}/{count}")
    public Result updateThumhup(@PathVariable("id") String id, @PathVariable("count") int count) {
        return forumService.updateThumhup(id, count);
    }

    @ApiOperation("根据用户ID查询话题列表")
    @PostMapping("/user")
    public IPage<Forum> findListByUserId(@RequestBody ForumUserREQ req) {
        return forumService.findListByUserId(req);
    }


    @ApiOperation("查询话题总记录数")
    @GetMapping("/total")
    public Integer questionTotal() {
        return forumService.getForumTotal();
    }


    @ApiOperation("查询今日帖子数量")
    @GetMapping("/search/count/day/num")
    public Integer searchCountDayNum() {
        return forumService.searchCountDayNum();
    }

    @ApiOperation("查询昨日帖子数量")
    @GetMapping("/search/count/yesterday/num")
    public Integer searchNumberOfArticlesInYesterdaySDay() {
        return forumService.searchNumberOfArticlesInYesterdaySDay();
    }

    @ApiOperation("查询近七天帖子数量")
    @GetMapping("/search/count/week/num")
    public Integer searchNumberOfArticlesInWeek() {
        return forumService.searchNumberOfArticlesInWeek();
    }

}
